package com.cxq.ssm.web;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cxq.ssm.domain.User;
import com.cxq.ssm.service.IUserService;

@Controller
@RequestMapping("/user")
public class UsreHandle {
	
	
	@Autowired
	@Qualifier("userService")
	private IUserService service;	
	
	
	@RequestMapping("/register")
	public String register(Model model,User user){
		int  result = service.userRegister(user);
		if(result>0){
			model.addAttribute("user",user);
			return "/WEB-INF/jsp/index.jsp";
		}
		return "/error.jsp";
	}
	
	@RequestMapping("/login")
	public String login(HttpSession session,User user){
		User userLogin = service.userLogin(user);
		if(userLogin!=null){
			session.setAttribute("user", user);
			return "/WEB-INF/jsp/show.jsp";
		}
		return "/error2.jsp";
	}
	

	@RequestMapping("/logout")
	public String logout(HttpSession session){
	session.invalidate();
	/*session.removeAttribute("user");*/
	return "/login.jsp";
	}
}